home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / CHEMPLOT.ZIP / TPlot / BCB Demo / Normal1.cpp < prev    next >
C/C++ Source or Header  |  2001-04-27  |  6KB  |  204 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3.  
  4. #include <math.h>
  5.  
  6. #pragma hdrstop
  7.  
  8. #include "Normal1.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "Plot"
  12. #pragma link "PlotMenu"
  13. #pragma link "NEdit"
  14. #pragma link "Nedit"
  15. #pragma link "Plotimagelist"
  16. #pragma link "Plotmenu"
  17. #pragma link "Plottoolbar"
  18. #pragma resource "*.dfm"
  19. TMainForm *MainForm;
  20. //---------------------------------------------------------------------------
  21. __fastcall TMainForm::TMainForm(TComponent* Owner)
  22.     : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TMainForm::FormCreate(TObject *Sender)
  27. {
  28.   Plot1->Align = alClient;
  29.   StringGrid1->Cells[0][0] = "Test:";
  30.   StringGrid1->Cells[0][1] = "Score:";
  31.   StringGrid1->ColWidths[0] = 60;
  32. }
  33. //---------------------------------------------------------------------------
  34.  
  35. void __fastcall TMainForm::ExitMenuItemClick(TObject *Sender)
  36. {
  37.   Close();
  38. }
  39. //---------------------------------------------------------------------------
  40.  
  41. void __fastcall TMainForm::GoBitBtnClick(TObject *Sender)
  42. {
  43.   Single X, Y;
  44.   Single Mean;
  45.   Single StdDev;
  46.   Single Min;
  47.   Single Max;
  48.   Single StepSize;
  49.   Integer TheSeries;
  50.   Single TheScore;
  51.   Integer i;
  52.   PSeries pMySeries;
  53.  
  54.   Plot1->SeriesList->ClearSeries();
  55.   Plot1->AddSeries(-1);
  56.  
  57.   Mean = MeanNEdit->AsReal;
  58.   StdDev = StdDevNEdit->AsReal;
  59.   Min = MinNEdit->AsReal;
  60.   Max = MaxNEdit->AsReal;
  61.   StepSize = StepSizeNEdit->AsReal;
  62.  
  63. //Set the axes:
  64.   Plot1->XAxis->Max = Max;
  65.   Plot1->XAxis->Min = Min;
  66.   Plot1->YAxis->Min = 0;
  67.   Plot1->XAxis->Intercept = 0;
  68.  
  69.   X = Min;
  70.   pMySeries = (PSeries) Plot1->SeriesList->Items[0];
  71.   do
  72.   {
  73.     Y = (X-Mean)/(2*StdDev);
  74.     Y = Y * Y;
  75.     Y = exp(-Y) / sqrt(2 * PI * StdDev);
  76. //Don't fire any events, and don't adjust axes:
  77.     pMySeries->AddPoint(X, Y, FALSE, FALSE);
  78.     X = X + StepSize;
  79.   } while (X <= Max);
  80.   pMySeries->Visible = TRUE;
  81.  
  82.   Plot1->YAxis->Min = Plot1->Series[0]->YMin;
  83.   Plot1->YAxis->Max = pMySeries->YMax;
  84.  
  85.   for (i = 1; i < StringGrid1->ColCount; i++)
  86.   {
  87.     if (StringGrid1->Cells[i][0].Length() > 0)
  88.     {
  89.       if (StringGrid1->Cells[i][1].Length() > 0)
  90.       {
  91.         try
  92.         {
  93.           TheScore = StrToFloat(StringGrid1->Cells[i][1]);
  94.           TheSeries = Plot1->AddSeries(-1);
  95.           pMySeries = (PSeries) Plot1->SeriesList->Items[TheSeries];
  96.           pMySeries->Name = StringGrid1->Cells[i][0];
  97.           pMySeries->AddPoint(TheScore, Plot1->YAxis->Min, TRUE, TRUE);
  98.           pMySeries->AddPoint(TheScore, Plot1->YAxis->Max, TRUE, TRUE);
  99.           pMySeries->Visible = TRUE;
  100.           pMySeries->Symbol = (TSymbol) fmod(i, 1+syDownTriangle);
  101.         }
  102.         __finally 
  103.         {}
  104.       }
  105.     }
  106.   }
  107.  
  108. }
  109. //---------------------------------------------------------------------------
  110.  
  111. void __fastcall TMainForm::PlotTypeBitBtnClick(TObject *Sender)
  112. {
  113.   Integer ThePlotType;
  114.  
  115.   ThePlotType = Plot1->PlotType;
  116.   ThePlotType++;
  117.  
  118.   if (ThePlotType == ptColumn+1) ThePlotType = 0;
  119.  
  120.   Plot1->SeriesList->ClearSeries();
  121.   Plot1->PlotType = (TPlotType) ThePlotType;
  122.   switch (Plot1->PlotType)
  123.   {
  124.     case ptXY:
  125.       Plot1->MakeDummyData(100);
  126.       break;
  127.     case ptMultiple:
  128.       Plot1->MakeDummyData(20);
  129.       break;
  130.     case ptColumn:
  131.       Plot1->MakeDummyData(10);
  132.       break;
  133.   }
  134. }
  135. //---------------------------------------------------------------------------
  136.  
  137. void __fastcall TMainForm::BitBtn3Click(TObject *Sender)
  138. {
  139.   Plot1->MakeDummyData(100);
  140. }
  141. //---------------------------------------------------------------------------
  142.  
  143. void __fastcall TMainForm::TraceBitBtnClick(TObject *Sender)
  144. {
  145.   Plot1->Trace();    
  146. }
  147. //---------------------------------------------------------------------------
  148.  
  149. void __fastcall TMainForm::ClearAllBitBtnClick(TObject *Sender)
  150. {
  151.   Integer i;
  152.  
  153.   Plot1->SeriesList->ClearSeries();
  154.   for (i = 1; i < StringGrid1->ColCount; i++)
  155.   {
  156.     StringGrid1->Cells[i][0] = "";
  157.     StringGrid1->Cells[i][1] = "";
  158.   }
  159. }
  160. //---------------------------------------------------------------------------
  161.  
  162. void __fastcall TMainForm::GoCrazyBitBtnClick(TObject *Sender)
  163. {
  164.   if (CrazyTimer->Enabled)
  165.   {
  166.     CrazyTimer->Enabled = FALSE;
  167.     GoCrazyBitBtn->Caption = "Go Crazy";
  168.     TraceBitBtn->Enabled = TRUE;
  169.   }
  170.   else
  171.   {
  172.     StartWidth = Width;
  173.     StartHeight = Height;
  174.     Angle = 0;
  175.     AngleInc = 4 * PI / 180;
  176.     GoCrazyBitBtn->Caption = "Enough !";
  177.     CrazyTimer->Enabled = TRUE;
  178.     TraceBitBtn->Enabled = FALSE;
  179.   }
  180. }
  181. //---------------------------------------------------------------------------
  182.  
  183. void __fastcall TMainForm::CrazyTimerTimer(TObject *Sender)
  184. {
  185.   Width = StartWidth + RADIUS * sin(Angle);
  186.   Height = StartHeight + RADIUS * cos(Angle);
  187.   Angle = Angle + AngleInc;
  188. }
  189. //---------------------------------------------------------------------------
  190.  
  191. void __fastcall TMainForm::Plot1FileOpen(TObject *Sender, AnsiString TheFile)
  192. {
  193.   AnsiString TheTitle;
  194.  
  195.   TheTitle = ExtractFileName(Application->ExeName);
  196.   //TheTitle = Copy(TheTitle, 1, Length(TheTitle)-4);
  197.   TheTitle.SetLength(TheTitle.Length()-4);
  198.   TheTitle = TheTitle + " - " + ExtractFileName(TheFile);
  199.   Application->Title = TheTitle;
  200.   MainForm->Caption = TheTitle;
  201. }
  202. //---------------------------------------------------------------------------
  203.  
  204.